﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Fly.Common;
using Fly.Common.WorkFlow;
using System.Text;
using RN.ERP.Web.EnterpriseService;
using Newtonsoft.Json;


namespace RN.ERP.Web.UserControl
{
    public partial class UCShenHeState : System.Web.UI.UserControl
    {
        #region 参数
        public string ClassId { get; set; }
        public string AreaCode { get; set; }
        public string FlowCode { get; set; }

        # endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetShenHeState();
            }
            
        }

        protected void SetShenHeState()
        {
            int Currentindex = 0;
            StringBuilder sb = new StringBuilder();

            List<ProgressNode> list = null;

            using (EnterpriseServiceClient client = new EnterpriseServiceClient())
            {
                string prostr = client.GetProgressNodes(ClassId, AreaCode, FlowCode);
                if (!string.IsNullOrEmpty(prostr))
                {
                    list = JsonConvert.DeserializeObject<List<ProgressNode>>(prostr);
                }
            }
            if (list == null)
            {
                return;
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].IsCurrent)
                    Currentindex = i;
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (i < Currentindex)
                {
                    sb.Append("<div class='proce ready'><ul><li class='tx1'>&nbsp;</li></ul></div>");
                    sb.Append("<div class='node ready'><ul><li class='tx1'>&nbsp;</li><li class='tx2'>" + list[i].Title + "</li></ul></div>");
                }
                else if (i == Currentindex)
                {
                    sb.Append("<div class='proce ready'><ul><li class='tx1'>&nbsp;</li></ul></div>");
                    sb.Append("<div class='node singular'><ul><li class='tx1'>&nbsp;</li><li class='tx2'>" + list[i].Title + "</li></ul></div>");
                }
                else
                {
                    sb.Append("<div class='proce wait'><ul><li class='tx1'>&nbsp;</li></ul></div>");
                    sb.Append("<div class='node wait'><ul><li class='tx1'>&nbsp;</li><li class='tx2'>" + list[i].Title + "</li></ul></div>");
                }
            }
            Literal1.Text = sb.ToString();
        }


    }

    
}